package chapter3.lessons.characterStreamPart;

import java.io.*;

/**
 * @Project ：learn_java
 * @File ：BufferedDemo01.java
 * @IDE ：IntelliJ IDEA
 * @Author ：自由如风间
 * @Date ：2025/3/1 10:39
 * @Description ：字符串缓冲输入和输出流
 */

public class BufferedDemo01 {
    public static void main(String[] args) throws IOException {
        // 创建字符缓冲输出流对象
        String filePath = "G:/codes/learn_java/IOTestOutputFiles/test.txt";

        // charWrite(filePath);

        charRead(filePath);
    }

    public static void charRead(String filePath) throws IOException {
        BufferedReader bfr = new BufferedReader(new FileReader(filePath));
        String line;
        while ((line = bfr.readLine()) != null) {
            System.out.println(line);
        }
        bfr.close();
    }

    public static void charWrite(String filePath) throws IOException {
        BufferedWriter bfw = new BufferedWriter(new FileWriter(filePath));
        for (int i = 0; i < 20; i++) {
            bfw.write(i + "line");
            bfw.newLine();
            bfw.flush();
        }
        bfw.close();
    }
}
